﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using OpenNETCF.IoC;
using OpenNETCF.MTConnect;

namespace MachineSimulator.Presenters
{
    public class AgentInfoPresenter : INotifyPropertyChanged
    {
        private string m_address;

        public event PropertyChangedEventHandler PropertyChanged;
        public event EventHandler RestartRequested;

        private IVirtualAgentService VirtualAgentService { get; set; }

        [InjectionConstructor]
        public AgentInfoPresenter([ServiceDependency]IVirtualAgentService agentService )
        {
            VirtualAgentService = agentService;
            VirtualAgentService.RestartRequested += new EventHandler(VirtualAgentService_RestartRequested);
            m_address = VirtualAgentService.AgentAddress.ToString();
        }

        void VirtualAgentService_RestartRequested(object sender, EventArgs e)
        {
            RestartRequested.Fire(this, e);
        }

        public string AgentAddress
        {
            get { return m_address; }
            internal set
            {
                m_address = value;
                RaisePropertyChanged("AgentAddress");
            }
        }

        private void RaisePropertyChanged(string property)
        {
            var handler = PropertyChanged;
            if (handler == null) return;
            handler(this, new PropertyChangedEventArgs(property));
        }
    }
}
